/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Aug 13, 2009 12:52:33 AM $
 *
 * Author: Eric Yang
 * Date  : Aug 13, 2009 12:52:33 AM
 *
 */
package com.gooex.web.action.gbuy.usercenter;

import org.c4j.string.StringTools;

import com.gooex.domain.organization.User;
import com.gooex.web.action.BaseProtectedAction;


/**
 * @author Eric Yang
 * @version 1.0
 */
public class SaveUserAction extends BaseProtectedAction {

	private User user;

	public String execute() throws Exception {
		if (user == null) {
			addActionError(getText("system.error"));
			return ERROR;
		}
		if (!StringTools.isBlankOrNull(user.getId())) {
			User currentUser = getCurrentUser();
			if (!user.getId().equals(currentUser.getId())) {
				addActionError(getText("system.error"));
				return ERROR;
			}
			currentUser.copyChangeableInfo(user);
			user = currentUser;
		}
		try {
			userManager.saveUser(user);
			addActionMessage("user.profile.save.success");
		} catch (Exception e) {
			addActionError(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
